package it.eng.get.pdfwe.jr.matcher;

import java.awt.Color;

import org.w3c.dom.Element;

/**
 * @author <div style="width: 100%; height: 2em;
 * background-repeat: repeat-x; 
 * background-image: url(http://www.mysoftworks.net/images/author_back.gif);" >
 * <a style="float: right; font-size: .9em; margin: 1.2em .5em .1em .1em; color: #658A16; color: 658A16; font-family: helvetica; font-weight: bold; text-decoration: none" href="http://www.mysoftworks.net">
 * Antonio Giovannetti for Engineering</a>
 * </div>
 */
public class DefaultElementMatcher implements ElementMatcher {

	public boolean elementMatches(Element elem) { // se la somma dei colori diviso 3 da resto 1
		if (elem==null) return false;
		String attr = elem.getAttribute("style");
		if (attr != null) {
			attr = attr.replaceAll(".*(color: )", "");
			attr = attr.replaceAll(";.*","");
			Color c = Color.decode(attr);
			int sum = c.getRed() + c.getGreen() + c.getBlue();
			return (sum % 3)==1;
			
		}
		return false;
	}

}
